package cn.com.listener;

import cn.com.wxUtil.WXUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created with IntelliJ IDEA.
 * User: yue
 * Date: 2018-03-30
 * Time: 23:16
 * Description:
 */
public class ApplicationInitListener implements ServletContextListener {

    private Logger logger= LoggerFactory.getLogger(ApplicationInitListener.class);

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        logger.info("程序初始化");
        Timer accessTokenTimer=new Timer();
//        定时时间,比微信规定的
        Long period=7100L*1000;
        accessTokenTimer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                WXUtil.getAccessToken();
            }
        },0,period);
        logger.info("成功初始化");
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
